{
    "cells": [
  {
   "cell_type": "markdown",
   "id": "cdbdaad6",
   "metadata": {},
   "source": [
    "# KISS-ICP running on the KITTI-Raw benchmark dataset\n",
    "\n",
    "The whole purpose of this notebook is to have a reproducable entry point for the experiments of the paper. You can also modify the system and just run this notebook to inspect the overall results.\n",
    "\n",
    "The main ingredient of this experiment is to test the \"deskew\" algoirthm we use.\n",
    "\n",
    "## Expected dataset layout\n",
    "\n",
    "```sh\n",
    "<data/kitti-odometry/raw>\n",
    "├── 2011_09_26\n",
    "│   ├── calib_cam_to_cam.txt\n",
    "│   ├── calib_imu_to_velo.txt\n",
    "│   └── calib_velo_to_cam.txt\n",
    "├── 2011_09_30\n",
    "│   ├── 2011_09_30_drive_0016_sync\n",
    "│   │   ├── image_00\n",
    "│   │   ├── image_01\n",
    "│   │   ├── image_02\n",
    "│   │   ├── image_03\n",
    "│   │   ├── oxts\n",
    "│   │   └── velodyne_points\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "584cfb31",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install KISS-ICP and Plotting tools\n",
    "%pip install kiss-icp ipympl evo >/dev/null\n",
    "\n",
    "import os\n",
    "from pathlib import Path\n",
    "\n",
    "import kiss_icp\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from evo.tools import plot\n",
    "from kiss_icp.datasets import dataset_factory\n",
    "from kiss_icp.pipeline import OdometryPipeline\n",
    "\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "%matplotlib widget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "676a6a26",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_root = os.environ.get(\"DATASETS\")\n",
    "kitti_root = Path(os.path.join(data_root, \"kitti-odometry/raw\"))\n",
    "print(f\"Reading datasets from : {data_root}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7795f59",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kiss_icp_eval import run_sequence\n",
    "\n",
    "\n",
    "def kitti_raw_sequence(sequence: int):\n",
    "    return OdometryPipeline(\n",
    "        dataset=dataset_factory(\n",
    "            dataloader=\"kitti_raw\",\n",
    "            data_dir=kitti_root,\n",
    "            sequence=sequence,\n",
    "        ),\n",
    "        deskew=True,\n",
    "    )\n",
    "\n",
    "\n",
    "results = {}\n",
    "for sequence in range(0, 11):\n",
    "    if sequence == 3:\n",
    "        continue\n",
    "    run_sequence(kitti_raw_sequence, sequence=sequence, results=results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb9e4e09",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kiss_icp_eval import print_metrics_table\n",
    "\n",
    "print_metrics_table(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1de1786d",
   "metadata": {},
   "source": [
    "## Trajectories Results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1747d471",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kiss_icp_eval import plot_trajectories\n",
    "\n",
    "plot_trajectories(results)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "vscode": {
   "interpreter": {
    "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
